Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mcap typescript flatbuffer encoding example #726

Merged
merged 8 commits into from
Nov 22, 2022
Merged

Conversation

snosenzo
Copy link
Contributor

@snosenzo snosenzo commented Nov 15, 2022

  • Added an example showing how to create an mcap file using flatbuffers encoding in typescript

  • schemas (not dependent, but uses output from compiling the added schemas) PR: Add Flatbuffer Schema Support schemas#70

@snosenzo snosenzo changed the title Add Mcap typescript flatbuffers encoding example Add Mcap typescript flatbuffer encoding example Nov 17, 2022
@snosenzo snosenzo marked this pull request as ready for review November 17, 2022 18:45
typescript/examples/flatbufferswriter/package.json Outdated Show resolved Hide resolved
export function buildGridMessage(builder: Builder, json: Grid): number {
const frameId = builder.createString(json.frame_id);

const pose = buildPose(builder, json.pose);
Copy link
Member

@jtbandes jtbandes Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a curiosity question: what is the builder itself for? It seems like the actual objects are created by calling startX...endX. Is the builder storing some shared state? Does the builder actually need to be passed in or could this function create its own builder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The builder as far as I cant tell allows for abstracted use of the underlying buffer, expansion of buffer and tracks how much of it is allocated. So when you start a new object on the buffer and add attributes to it it allocates a given space for it in the continuous chunk and tracks where the next object can begin. It also allows the buffer to have a root schema, hence the importance of ending the buffer with the main message type. All of the fields and data in a message have to be in the same buffer so when you create/end a Quaternion the index of that quaternion needs to be used when adding it to the object of the schema that includes it so that it can reference it in the same buffer.

Comment on lines 30 to 36
function roundUp(numToRound: number, multiple: number) {
if (multiple !== 0 && (multiple & (multiple - 1)) === 0) {
return (numToRound + multiple - 1) & -multiple;
} else {
throw Error(`invalid multiple ${multiple}, num to round ${numToRound}`);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just use lodash round() or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just simplified this code. Not sure if there's a lodash equivalent. It's not strictly necessary but nice to have

typescript/examples/flatbufferswriter/scripts/main.ts Outdated Show resolved Hide resolved
typescript/examples/flatbufferswriter/scripts/main.ts Outdated Show resolved Hide resolved
typescript/examples/flatbufferswriter/scripts/main.ts Outdated Show resolved Hide resolved
typescript/examples/flatbufferswriter/scripts/main.ts Outdated Show resolved Hide resolved
typescript/examples/flatbufferswriter/scripts/main.ts Outdated Show resolved Hide resolved
@snosenzo snosenzo merged commit 0903d18 into main Nov 22, 2022
@snosenzo snosenzo deleted the flatbuffer-encoding branch November 22, 2022 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants